<!doctype html>
<html>
	<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0">
		<meta name="format-detection" content="telephone=no">
		<title>签到</title>
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/public.css">
		<link rel="stylesheet" href="../css/signin.css">
	</head>

	<body style="">
		<header class="mui-bar mui-bar-nav">
			<a style="color: #007aff;" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">签到</h1>
		</header>
		<div style="margin-top:50px;" class="top flex flex-align-end flex-pack-center flex-warp">
			<div class="out-1 flex flex-align-center flex-pack-center" id="signIn">
				<div class="out-2 flex flex-align-center flex-pack-center">
					<div class="signBtn">
						<strong id="sign-txt">签到</strong>
						<span>已签到<em id="sign-count">1</em>天</span>
					</div>
				</div>
			</div>
		</div>
		<div class="Calendar">
			<div id="toyear" class="flex flex-pack-center">
				<div id="idCalendarPre">&lt;</div>
				<div class="year-month">
					<span id="idCalendarYear">2019</span>年<span id="idCalendarMonth">2</span>月
				</div>
				<div id="idCalendarNext">&gt;</div>
			</div>
			<table border="1px" cellpadding="0" cellspacing="0">
				<thead>
					<tr class="tou">
						<td>日</td>
						<td>一</td>
						<td>二</td>
						<td>三</td>
						<td>四</td>
						<td>五</td>
						<td>六</td>
					</tr>
				</thead>
				<tbody id="idCalendar"><tr><td><span>&nbsp;</span></td><td><span>&nbsp;</span></td><td><span>&nbsp;</span></td><td><span>&nbsp;</span></td><td><span>&nbsp;</span></td><td><span>1</span></td><td><span>2</span></td></tr><tr><td><span>3</span></td><td><span>4</span></td><td><span>5</span></td><td><span>6</span></td><td><span>7</span></td><td><span>8</span></td><td><span>9</span></td></tr><tr><td><span>10</span></td><td><span>11</span></td><td><span>12</span></td><td class="onToday"><span>13</span></td><td><span>14</span></td><td><span>15</span></td><td><span>16</span></td></tr><tr><td><span>17</span></td><td><span>18</span></td><td><span>19</span></td><td><span>20</span></td><td><span>21</span></td><td><span>22</span></td><td><span>23</span></td></tr><tr><td><span>24</span></td><td><span>25</span></td><td><span>26</span></td><td><span>27</span></td><td><span>28</span></td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody>
			</table>
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/jquery.min-1.11.1.js"></script>
		<script type="text/javascript" src="../js/rili.js"></script>
		<script language="JavaScript">
			mui.init()
			var myday =new Array(); //已签到的数组
			Date.prototype.Format = function (fmt) { // author: meizz
				var o = {
					"M+": this.getMonth() + 1, // 月份
					"d+": this.getDate(), // 日
					"h+": this.getHours(), // 小时
					"m+": this.getMinutes(), // 分
					"s+": this.getSeconds(), // 秒
					"q+": Math.floor((this.getMonth() + 3) / 3), // 季度
					"S": this.getMilliseconds() // 毫秒
				};
				if (/(y+)/.test(fmt))
					fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
					if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
						return fmt;
			}
			var myDate = new Date().Format("yyyy-MM-dd hh:mm:ss");
			//获取变量
			var self = localStorage.getItem("name")
			var dataold = JSON.parse(self)
			var now = new Date();
			var theday = now.getDate();
			console.log(dataold.obj.basicId,"999")
			fn();
			function fn(){
				$.ajax({
					type: 'post',
 					url:"http://192.168.2.64:8089/mobile/SysSignIn/getSignedThisMonth",
 					data:{
 							userId:dataold.obj.basicId
 						},
 					dataType:"json",
 					success : function(data) {
						var tf = data.obj.signedDays
 						if(data.status==1){
							for(var x=0; x<tf.length; x++){
								var day = ""
								if(tf[x] == true){
									day = x+1;
									var tb = document.getElementById('idCalendar')
									for(var i = 0; i < tb.rows.length; i++) {
										for(var j = 0; j < tb.rows[i].cells.length; j++) {
											if(day == tb.rows[i].cells[j].innerText) {
												tb.rows[i].cells[j].className = "onToday"
												if(tf[theday-1] == true){
													document.getElementById("sign-txt").innerHTML = '已签到';
												}
											}
										}
									}
								}
							}
							myday = document.getElementsByClassName("onToday");
							document.getElementById("sign-count").innerHTML = myday.length //已签到次数
 						}else{
 							
 						}
 					}
 				})
			}
			var isSign = false;

			var cale = new Calendar("idCalendar", {
				qdDay: myday,
				onToday: function(o) {
					o.className = "onToday";
				},
				onSignIn: function (){
					$$("sign-txt").innerHTML = '已签到';
				},
				onFinish: function() {
					$$("sign-count").innerHTML = myday.length //已签到次数
					$$("idCalendarYear").innerHTML = this.Year;
					$$("idCalendarMonth").innerHTML = this.Month; //表头年份

				}
			});
			$$("idCalendarPre").onclick = function() {
				cale.PreMonth();
			}
			$$("idCalendarNext").onclick = function() {
				cale.NextMonth();
			}
			//添加今天签到
			$$("signIn").onclick = function() {
				$.ajax({
					type: 'post',
					url:"http://192.168.2.64:8089/mobile/SysSignIn/sign",
					data:{
							userId:dataold.obj.basicId,
							signDate:myDate
						},
					dataType:"json",
					success : function(data) {
						if(isSign == false) {
							var res = cale.SignIn();
							if(res == '1') {
								$$("sign-txt").innerHTML = '已签到';
								$$("sign-count").innerHTML = parseInt($$("sign-count").innerHTML) + 1;
								isSign = true;
							} else if (res == '2'){
								$$("sign-txt").innerHTML = '已签到';
								mui.alert('今天已经签到了')
							}
						} else {
							mui.alert('今天已经签到了')
						}
					}
				})
			} 
		</script>
	</body>
</html>